package cn.itcast.web.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/*
* Session快速入门:使用Session共享数据
*/
@WebServlet("/sessionservletDemo1")
public class SessionServletDemo1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //1.获取session(即由request内置对象调用api创建一个HttpSession对象来存放数据)
        HttpSession session=request.getSession();
        //2.存储数据
        session.setAttribute("msg","hello,session");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doPost(request, response);
    }
}
